package j20251117;

import java.io.FileOutputStream;
import java.io.IOException;

public class Demo3 {
    public static void main(String[] args) {
        String content = "Hello, Java文件读写!";

        try (FileOutputStream fos = new FileOutputStream("output.txt")) {
            // 将字符串转换为字节数组并写入文件
            byte[] bytes = content.getBytes();
            fos.write(bytes);
            System.out.println("文件写入成功!");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
